package responsible.pojo;

public abstract class AbstractLogger {
    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;
    protected int level ;

    //责任链中的下一个元素
    protected AbstractLogger nextLogger;
    public void setNextLogger(AbstractLogger nextLogger){
        this.nextLogger = nextLogger;
    }

    public void logMessage(int level,String message){
        if (nextLogger!=null){
            nextLogger.logMessage(level,message);
        }
        if (this.level<=level){
            nextLogger =  new ConsoleLogger(this.level);
            nextLogger.write(message);
        }else {
            nextLogger = new InfoLogger(level);
            nextLogger.write(message);
        }

    }

    abstract void write(String message);
}
